<html>
<head><meta charset="utf-8"><title>why isn&#x27;t `inline(always)` used? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/why.20isn&#x27;t.20.60inline(always).60.20used.3F.html">why isn&#x27;t `inline(always)` used?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239653364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/why%20isn%27t%20%60inline%28always%29%60%20used%3F/near/239653364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/why.20isn&#x27;t.20.60inline(always).60.20used.3F.html#239653364">(May 20 2021 at 20:21)</a>:</h4>
<p>I just noticed PR <a href="https://github.com/rust-lang/rust/issues/84560">#84560</a>, and that originally it tried adding <code>#[inline(always)]</code> but it made performance worse. Yet the body of the function is literally just <code>self</code>. So I have two questions:</p>
<ul>
<li>How could inlining that make runtime <em>worse</em> (I would think it'd be better both because IIUC there would be less monomorphization, so instruction cache is not polluted, and because a jump is avoided)? (Maybe this question is more suited to the compiler team though...)</li>
<li>Why is <code>#[inline(always)]</code> avoided in general in the stdlib?</li>
</ul>
<p>Thanks!</p>



<a name="239654081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/why%20isn%27t%20%60inline%28always%29%60%20used%3F/near/239654081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/why.20isn&#x27;t.20.60inline(always).60.20used.3F.html#239654081">(May 20 2021 at 20:27)</a>:</h4>
<p>Because <code>always</code> is a very big hammer.  In an optimized build, so long as the definition is available LLVM will inline a trivial body even without the attribute, so the situations in which it's worth using the extra-big hammer are quite narrow -- often it's just about what happens in debug builds.</p>
<p>Most of the time it's completely appropriate to let LLVM <em>not</em> inline something if it thinks it's a bad idea to inline it.</p>



<a name="239656313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/why%20isn%27t%20%60inline%28always%29%60%20used%3F/near/239656313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/why.20isn&#x27;t.20.60inline(always).60.20used.3F.html#239656313">(May 20 2021 at 20:42)</a>:</h4>
<p>It might also shuffle inlining boundaries around in a way that the hot code gets optimized less because the function is now too big or something like that</p>



<a name="239661844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/why%20isn%27t%20%60inline%28always%29%60%20used%3F/near/239661844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/why.20isn&#x27;t.20.60inline(always).60.20used.3F.html#239661844">(May 20 2021 at 21:25)</a>:</h4>
<p>Adding / removing an inline attribute to a function with as many instantiations as <code>into_iter</code> tends to completely change the CGU partitioning.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>